<?php
namespace Home\Controller;
use Think\Controller;

class IndexController extends Controller {
    
    /**
    * 主页面函数
    */
    public function index(){
        //var_dump(session('?username'));exit;
        if(session('?username')){
            $username = I('get.username')?I('get.username'):session('username');
            $this->assign('hidden2','hidden');
            $this->assign('username',$username);
        }
        $model3 = D('Admin/Cate');
        $tree = $model3->catelist();
        $model2 = D('Goods');
        $this->assign('tree',$tree);

        $best1 = $model2->where('is_best = 1')->order('goods_id desc')->limit(0,3)->select();
        $this->assign('best',$best1);

        $new1 = $model2->where('is_new = 1')->order('goods_id desc')->limit(0,3)->select();
        $this->assign('new',$new1);
        
        $hot1 = $model2->where('is_hot = 1')->order('goods_id desc')->limit(0,3)->select();
        $this->assign('hot',$hot1);
        $this->display();
    }


    //以下函数都没有使用！！！！！！

    public function add1(){
    	 $md = D('Goods');
         $md->name='lisi';
         $md->age ='22';
         $md->color = "yellow";
         $md->add();
    }
    
    //查询单条信息  通过主键
    public function search(){
        $md = D('Goods');
        var_dump($md->find(2));
    }

    //查询多条信息  通过where条件进行查询
    public function searches(){
        $md = D('Goods');
        var_dump($md->where('id>=6')->select());
    }

    //修改内容
    public function modify(){
        $md = D('Goods');
        $md->name = 'zhangsan';
        $md->age = '20';
        $md->color = 'blue';
        var_dump($md->where('id=3')->save());
    }

    //删除操作
    public function delete(){
        $md = D('Goods');
        $md->delete('1,2');
    }

    public function cat(){
        $cat_id = I('cat_id');
        //var_dump($cat_id);exit;
        $catModel = D('Admin/Cate'); //注意这个地方是正斜线
        $tree = $catModel->catelist();
        $this->assign('tree',$tree);

        $goodsModel = D('Admin/Goods');
        
        //var_dump($vl);exit;
        $value3 = $goodsModel->where("cat_id = $cat_id")->order('goods_id desc')->select();
        //var_dump($value3);exit;
        $this->assign('category',$value3);
        $this->display();
    }
    
}
